package main

import (
	"context"
	"fmt"

	"github.com/micro/go-micro"
	proto "micro-learning/proto/greeter"
)

type Greeter struct{}

func (g *Greeter) Hello(ctx context.Context, req *proto.HelloRequest, rsp *proto.HelloResponse) error {
	rsp.Greeting = "Hello " + req.Name
	return nil
}

/*

	Function是指接收一次请求，执行后便退出的服务


*/
func main() {

	// create a new function
	fnc := micro.NewFunction(
		micro.Name("greeter"),
	)

	// init the command line
	fnc.Init()

	// register a handler
	fnc.Handle(new(Greeter))

	// run the function
	if err := fnc.Run(); err != nil {
		fmt.Println(err)
	}

	fmt.Println("-------------------------")
}